package com.honyelchak.shortlink.admin.util;

import java.security.SecureRandom;

public final class RandomGenerator {
    private static final String CHARACTERS = "O123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    private static final SecureRandom RANDOM = new SecureRandom();

    public static String generateRandom() {
        return generateRandom(6);
    }

    public static String generateRandom(int length) {
        StringBuilder sb = new StringBuilder(length);
        for(int i = 0; i < length; i++) {
            int randomIndex = RANDOM.nextInt(CHARACTERS.length());
            sb.append(CHARACTERS.charAt(randomIndex));
        }
        return sb.toString();
    }
    public static void main(String[] args){
        String randomString = generateRandom(6);
        System.out.println(randomString);
    }
}
